<%--
    Document   : danhmuc_sua
    Created on : Dec 19, 2011, 9:50:47 AM
    Author     : kydrenw
--%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<script type="text/javascript">
    function enableText(id)
    {
        var element = document.getElementById(id);
        element.disabled = false;
        element.style.background="#FFF";
        document.getElementById("btn"+id).style.display="block";
    }

    function disable(id)
    {
        var element = document.getElementById(id);
        element.disabled = true;
        element.style.background="#CFEA8B";
        document.getElementById("btn"+id).style.display="none";
    }

    function changeName(id)
    {
        var value = document.getElementById(id).value;
        document.getElementById("ten"+id).value=value;
    }
</script>

<div class="box-head">${danhmuc.ten}</div>
<form method="post" action="danhmuc.htm" style="float:left; margin-left: 10px;">
    <div class="textcenter">
        <span>Tên danh mục</span>
        <input type="hidden" name="madanhmuc" value="${danhmuc.ma}"/>
        <span><input type="text" name="tendanhmuc" value="${danhmuc.ten}"/></span>
        <span><input type="submit" value="Change"/></span>
    </div>
</form>
<form action="danhmuc.htm" method="post" name="frm_timdm" id="frm_timdm" onsubmit="return check_tim_sp()" class="formSearch" style="float:right">
    <div>
        <span>
            <input type="hidden" name="action" value="timkiem_loaisp"/>
            <input type="hidden" name="madm" value="${danhmuc.ma}"/>
            <input name="txttukhoa" type="search" id="txttukhoa" placeholder="Tìm ..."/>
            <input type="submit" name="Submit" value="" class="btn btnSearch" title="Tìm"/>
        </span>
        <span>
            <input type="button" value="" class="btn btnAdd" onclick="show('frm_ThemLoai')" title="Thêm loại sản phẩm"/>
        </span>
    </div>
</form>
<form action="danhmuc.htm" method="post"  onsubmit="return themloaisp()">
    <div style="display: none" id="frm_ThemLoai">
        <input type="hidden" name="action" value="themloaisp_submit"/>
        <input type="hidden" name="madm" value="${danhmuc.ma}"/>
        <input type="text"  name="txtTenLoaiSP" id="txtTenLoaiSP" placeholder="Tên loại sản phẩm ..."/>
        <input type="submit" name="Submit" value="Thêm"/>
    </div>
</form>
<table width="100%">
    <tr>
        <td class="tbhead">Loại sản phẩm</td>
        <td class="tbhead">Xóa</td>
        <td class="tbhead">Thao tác</td>
    </tr>
    <c:forEach var="item" items="${dsLoai}">
        <tr>
            <td class="tbcontent">
                <form action="danhmuc.htm" method="post" onsubmit="disable(${item.ma})">
                    <input type="hidden" name="maLoai" value="${item.ma}"/>
                    <input id="${item.ma}" type="text" value="${item.ten}" disabled="true" class="textLoai" onchange="changeName(${item.ma})"/>
                    <input id="ten${item.ma}" type="hidden" name="tenLoai" value="${item.ten}"/>
                    <input type="hidden" name="action" value="suaLoai"/>
                    <input type="hidden" name="madanhmuc" value="${danhmuc.ma}"/>
                    <input id="btn${item.ma}" type="submit" class="btn btnSubmit" value="" style="display: none"/>
                </form>
            </td>
            <td class="tbcontent textcenter">
                <c:if test="${item.xoa==1}">
                    <img src="/images/isdel.png"/>
                </c:if>
            </td>
            <td class="tbcontent">
                <input title="Sửa" type="button" class="btn btnEdit" onclick="enableText(${item.ma})"/>
                <input title="Bỏ xóa" type="button" class=" btn btnSubmit" onclick="window.location='danhmuc.htm?action=boxoa&dm=${danhmuc.ma}&ma=${item.ma}'"/>
                <input title="Xóa" type="button" class=" btn btnDel" onclick="return confirm('Bạn có chắc chắn muốn xóa không ?'), window.location='danhmuc.htm?action=xoaloai&dm=${danhmuc.ma}&ma=${item.ma}'"/>
            </td>
        </tr>
    </c:forEach>
</table>
<div class="command">
    <input class="button" type="button" value="Quay lại" onclick="window.location='danhmuc.htm'"/>
</div>